package com.woniu.controller.homepage;

import com.woniu.entity.Carts;
import com.woniu.entity.OrdersDetails;
import com.woniu.service.homePage.ICartsService;
import com.woniu.util.ResData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 周权
 * @data 2023/3/6 11:45
 */
@RestController
@RequestMapping("/app")
public class CartsController {

    @Autowired
    ICartsService cartsService;

    @RequestMapping("/queryCarts")
    public ResData<?> queryCartsData(String phone) {
        return cartsService.queryUserCarts(phone);

    }

    @RequestMapping("/queryCount")
    public ResData<?> queryCartscount(String phone) {
        return cartsService.queryCartscount(phone);

    }

    @PostMapping("/addUserCarts")
    public ResData<?> addUserCarts(@RequestBody Carts carts) {
        return cartsService.addUserCarts(carts);
    }

    @RequestMapping("/updateChecked")
    public ResData<?> updateChecked( Integer id) {
        return cartsService.updateChecked(id);

    }

    @RequestMapping("/updateCartNum")
    public ResData<?> updateCartGoodsNum(@RequestBody Carts carts) {
        return cartsService.updateCartGoodsNum(carts);
    }

    @GetMapping("/queryGoodsByPrice")
    public ResData<?> queryGoodsByPrice() {
      return cartsService.queryGoodsByPrice();
    }


    @RequestMapping("/addOrders")
    public ResData<?> addOrders(@RequestBody  List<Integer> cartsIds) {
    return cartsService.buyOrders(cartsIds);
    }
    @RequestMapping("/deleteCartsGoods")
    public ResData<?> deleteCartsGoods(Integer id){
       return cartsService.deleteCartsGoods(id);
    }
    @RequestMapping("/updateCount")
    public ResData<?> updateCount(@RequestBody List<OrdersDetails> ordersDetailsList){
        return cartsService.updateCount(ordersDetailsList);
    }
}